<div class="row">
	<div class="col-sm-12" style="width: 99%;">
		<div class="nest" id="treeClose">
			<div class="title-alt">
				<h6>Thiết bị</h6>
			</div>

			<div class="body-nest" id="tree" style="min-height: 490px">
    				<div class="row">
                        <div class="col-sm-5">
                        <div class="nest" id="validationClose">
                            <div class="title-alt" style="margin: 0px auto 0;">
                                <h6><?php echo $type == 'edit' ? 'Sửa' : 'Thêm'?> thiết bị</h6>
                                <div class="titleToggle">
                                    <a class="nav-toggle-alt" href="#validation">
                                        <span class="entypo-up-open"></span>
                                    </a>
                                </div>
                            </div>
                            <div class="body-nest" id="validation">
                                <div class="form_center" style="width: 90%;">
                                    <?php if(validation_errors() || @$error || @$zero):?>
                                    
                                    <div class="alert alert-danger">
                                        <button data-dismiss="alert" class="close" type="button">×</button>
                                        <span class="entypo-attention"></span>
                                        <strong>Oh lỗi!</strong>&nbsp;&nbsp;<?php echo validation_errors(); ?>
                                        <?php if(@$error):?>
                                        <br />
                                        <?php echo $error?>
                                        <?php endif;?>
                                        <?php if(@$zero):?>
                                        <br />
                                        <script>
                                        jAlert('Vui lòng chọn địa chỉ', 'Thông báo', function()
                                        {
                                            window.location = '<?php echo site_url().'/device'?>'; 
                                        });
                                        </script>
                                        <?php endif;?>
                                        
                                    </div>
                                    <?php endif;?>
                                    <?php if(@$status):?>
                                        <script>
                                        jAlert('<?php echo $status;?>', 'Thông báo', function()
                                        {
                                            window.location = '<?php echo site_url().'/device'?>'; 
                                        });
                                        </script>
                                    <?php endif;?>
                                    <?php $att = array('id' => 'contact-form', 'class' => 'form-horizontal', 'enctype' => 'multipart/form-data'); echo form_open('', $att);?>
                                        <input type="hidden" name="id" value="<?php echo $id?>" />
                                        <input type="hidden" name="type" value="<?php echo $type?>" />
                                        <fieldset>
                                            <div class="control-group">
                                                <label class="control-label" for="name">Chọn địa điểm</label>
                                                <div class="controls">
                                                    <?php echo $fview->selectOption($place, @$dataedit->id_address ? @$dataedit->id_address : $this->input->post('place'), 'form-control', 'place', 'place');?>
                                                </div>
                                            </div>
                                            <div class="control-group">
                                                <label class="control-label" for="subject">Tên thiết bị <small style="color:  red;">(*)</small></label>
                                                <div class="controls">
                                                    <input type="text" class="form-control" value="<?php echo @$dataedit->namedevice ? @$dataedit->namedevice : $this->input->post('namedevice')?>" name="namedevice" id="namedevice" />
                                                </div>
                                            </div>
                                            <div class="control-group">
                                                <label class="control-label" for="subject">Mac thiết bị <small style="color:  red;">(*)</small></label>
                                                <div class="controls">
                                                    <input type="text" class="form-control" value="<?php echo @$dataedit->mac ? @$dataedit->mac : $this->input->post('mac')?>" name="mac" id="mac" />
                                                </div>
                                            </div>
											<div class="control-group">
                                                <label class="control-label" for="subject">NasID thiết bị <small style="color:  red;">(*)</small></label>
                                                <div class="controls">
                                                    <input type="text" class="form-control" value="<?php echo @$dataedit->nasid ? @$dataedit->nasid : $this->input->post('nasid')?>" name="nasid" id="nasid" />
                                                </div>
                                            </div>
                                            <div class="control-group">
                                                <label class="control-label" for="subject">File cấu hình ( .Zip )</label>
                                                <div class="controls">
                                                    <input type="file" class="form-control" name="fileconfig" />
                                                    <?php if(@$id):?>
                                                    <br /><b>Link: </b>
                                                    <a href="<?php echo site_url().'public/'.$dataedit->linkupdate?>">
                                                        <?php echo $dataedit->linkupdate?>
                                                    </a>
                                                    <?php endif;?>
                                                </div>
                                            </div>
                                            <div class="control-group">
                                                <label class="control-label" for="subject">Version hotspot <small style="color:  red;">(*)</small></label>
                                                <div class="controls">
                                                    <input type="text" class="form-control" value="<?php echo @$dataedit->version ? @$dataedit->version : $this->input->post('version')?>" name="version" id="version" />
                                                </div>
                                            </div>
                                            
                                            <div class="control-group">
                                                <label class="control-label" for="name">Kiểu thiết bị</label>
                                                <div class="controls">
                                                    <select class="form-control" name="types" id="type">
														<?php foreach ( $geturlhomepage AS $el=>$le ){ ?>
															<option <?php if( @$dataedit->type == $le->id ){ echo 'selected="selected"'; } ?>  value="<?php echo $le->id;?>"><?php echo $le->note;?></option>
														<?php } ?>
													</select>
												</div>
                                            </div>
                                            
                                            <div class="control-group">
                                                <label class="control-label" for="name">Trạng thái</label>
                                                <div class="controls">
                                                    <?php echo $fview->selectOption(array('1' => 'Hoạt động','0' => 'Không hoạt động'), @$dataedit->active ? @$dataedit->active : $this->input->post('active'), 'form-control', 'active', 'active');?>
                                                </div>
                                            </div>
                                            
                                            <div class="form-actions" style="margin:20px 0 0 0;float: right">
                                                <button type="submit" class="btn btn-primary ">Đồng ý</button>
                                            </div>
                                        </fieldset>
                                    </form>

                                </div>
                            </div>
                        </div>
                    </div>
    					<div class="col-sm-7">
    						<div class="nest" id="tableStaticClose">
                            <div class="title-alt" style="margin: 0px auto 0;">
                                <h6>Danh sách thiết bị</h6>
                                <div class="titleToggle">
                                    <a class="nav-toggle-alt" href="#tableStatic">
                                        <span class="entypo-up-open"></span>
                                    </a>
                                </div>

                            </div>

                            <div class="body-nest" id="tableStatic">

                                <section id="flip-scroll">

                                    <table class="table table-bordered table-striped cf">
                                        <thead class="cf">
                                            <tr>
                                                <th>STT</th>
                                                <th>Tên thiết bị</th>
												<th>NasID</th>
                                                <th>Địa điểm</th>
                                                <th>Quận/Huyện-Tỉnh/TP</th>
                                                <th>Trạng thái</th>
                                                <th>Tác vụ</th>
                                            </tr>
                                        </thead>
                                        <tbody>
										
										
                                        <?php if($data):?>
                                            <?php foreach($data AS $el=>$le):?>
                                            <tr <?php echo ($le->did == $id) ? 'class="show-edit"' : '';?>>
                                                <td><?php echo ($el + 1)?></td>
                                                <td><?php echo $le->namedevice?></td>
												 <td><?php echo $le->nasid?></td>
                                                <td><?php echo $le->address?></td>
                                                <td><?php echo $le->dname.' '.$le->pname?></td>
                                                <td><?php echo $fview->Cactive($le->active)?></td>
                                                <td>
                                                <a href="<?php echo site_url().'device?type=edit&id='.$le->did?>">
                                                    Sửa
                                                </a>
                                                 | 
                                               <!-- <a href="<?php echo site_url().'device?type=delete&id='.$le->did?>">
                                                    Xóa
                                                </a> -->
												<a style="cursor: pointer;" id="<?php echo $le->did;?>" class="del_item">Xóa</a>
												
                                                </td>
                                            </tr>
                                            <?php endforeach;?>
                                        <?php endif;?>
                                        
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <td colspan="6" id="pagination"><?php echo $this->pagination->create_links();?></td>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </section>

                            </div>

                        </div>

    					</div>
    				</div>
			</div>
		</div>
	</div>
    <style>
    #pagination{
        
    }
    #pagination a{
            padding: 3px 10px;
            margin: 10px 2px;
            border: 1px solid #CCC;
            background: #CCC;
            color: #FFF;
    }
    #pagination strong{
            padding: 3px 10px;
            margin: 10px 2px;
            border: 1px solid #CCC;
    }

    </style>
    <script>
        $(document).ready(function()
        {
            $("#province").on('change', function()
            {
               var id_province = $(this).val();
               $("#district_select").html('<input type="text" value="Plz, waitting..." class="form-control" name="">');
               $.ajax({
                    type: 'get',
                    url: '<?php echo site_url('get-district');?>',
                    data: ({id: id_province}),
                    success: function(_data)
                    {
                        $("#district_select").html(_data);
                    }
               });
            }); 
			
			$('.del_item').click(function(){
				var r = confirm("Bạn có chắc chắn xóa thiết bị này không?");
				if (r == true) {
					window.location = '<?php echo site_url().'device?type=delete&id=';?>'+this.id;
				}else {
					return false;
				}
			});	
        })
    </script>
</div>